package com.lgywin.runserver.server;

import com.lgywin.runserver.entity.GameServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class InitServer {
    @Value("${netty_ip}")
    public String ip;

    @Value("${netty_port}")
    public int port;

    @Autowired
    com.lgywin.runserver.service.GameServerService gameServerService;

    public void init() {

        //设置区服
        GameServer find = gameServerService.find(ip,port);
        if(find == null || find.getId() == null){
            GameServer bean = new GameServer();
            bean.setName(ip+":"+port);
            bean.setState(1);
            bean.setIp(ip);
            bean.setPort(port);
            bean.setAddress("这是第一个区服");
            gameServerService.insert(bean);
        }else{
            find.setState(1);
            gameServerService.update(find);
        }
    }
}
